1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.webphotos.model;
17
18 import java.io.Serializable;
19 import java.util.ArrayList;
20 import java.util.Date;
21 import java.util.HashSet;
22 import java.util.Set;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.ManyToOne;
32 import javax.persistence.NamedQueries;
33 import javax.persistence.NamedQuery;
34 import javax.persistence.OneToMany;
35 import javax.persistence.Table;
36 import javax.persistence.Temporal;
37 import javax.persistence.TemporalType;
38 import net.sf.webphotos.entity.HasID;
39
40
41
42
43
44 @Entity
45 @Table(name = "ALBUNS")
46 @NamedQueries({
47 @NamedQuery(name = "AlbumVO.findByAlbumID", query = "SELECT a FROM AlbumVO a WHERE a.albumid = :albumid"),
48 @NamedQuery(name = "AlbumVO.findByNmAlbum", query = "SELECT a FROM AlbumVO a WHERE a.nmalbum = :nmalbum"),
49 @NamedQuery(name = "AlbumVO.findByDtInsercao", query = "SELECT a FROM AlbumVO a WHERE a.dtInsercao = :dtInsercao"),
50 @NamedQuery(name = "AlbumVO.findByCategoriaID", query = "SELECT a FROM AlbumVO a WHERE a.categoriasVO.categoriaID = :categoriaID")
51 })
52 public class AlbumVO implements Serializable, HasID<Integer> {
53
54 private static final long serialVersionUID = 1L;
55
56 @Id
57 @Column(name = "ALBUMID", nullable = false)
58 @GeneratedValue(strategy = GenerationType.IDENTITY)
59 private Integer albumid;
60
61 @Column(name = "NMALBUM", nullable = false)
62 private String nmalbum;
63
64 @Column(name = "DESCRICAO", nullable = true)
65 private String descricao;
66
67 @Column(name = "DTINSERCAO", nullable = false)
68 @Temporal(TemporalType.DATE)
69 private Date dtInsercao;
70
71 @ManyToOne
72 @JoinColumn(name = "CATEGORIAID", nullable = false)
73 private CategoryVO categoriasVO;
74
75 @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "album")
76 private Set<PhotoVO> photos;
77
78 public CategoryVO getCategoriasVO() {
79 return categoriasVO;
80 }
81
82 public void setCategoriasVO(CategoryVO categoriasVO) {
83 this.categoriasVO = categoriasVO;
84 }
85
86 @Deprecated
87 public AlbumVO() {
88 }
89
90 AlbumVO(String nmalbum, String descricao, Date dtInsercao, CategoryVO categoriasVO, Set<PhotoVO> photos) {
91 this.nmalbum = nmalbum;
92 this.descricao = descricao;
93 this.dtInsercao = dtInsercao;
94 this.categoriasVO = categoriasVO;
95 this.photos = photos;
96 }
97
98 AlbumVO(Integer key, String nmalbum, String descricao, Date dtInsercao, CategoryVO categoriasVO, Set<PhotoVO> photos) {
99 this(nmalbum, descricao, dtInsercao, categoriasVO, photos);
100 this.albumid = key;
101 }
102
103 public static AlbumVOBuilder builder() {
104 return new AlbumVOBuilder();
105 }
106
107 public static AlbumVOBuilder builder(Integer key) {
108 return new AlbumVOBuilder(key);
109 }
110
111
112
113
114
115 public Integer getAlbumid() {
116 return albumid;
117 }
118
119
120
121
122
123 public void setAlbumid(Integer albumid) {
124 this.albumid = albumid;
125 }
126
127
128
129
130
131 public String getNmalbum() {
132 return nmalbum;
133 }
134
135
136
137
138
139 public void setNmalbum(String nmalbum) {
140 this.nmalbum = nmalbum;
141 }
142
143
144
145
146 public String getDescricao() {
147 return descricao;
148 }
149
150
151
152
153 public void setDescricao(String descricao) {
154 this.descricao = descricao;
155 }
156
157
158
159
160
161 public Date getDtInsercao() {
162 return dtInsercao;
163 }
164
165
166
167
168
169 public void setDtInsercao(Date dtInsercao) {
170 this.dtInsercao = dtInsercao;
171 }
172
173 @Override
174 public int hashCode() {
175 int hash = 0;
176 hash += (albumid != null ? albumid.hashCode() : 0);
177 return hash;
178 }
179
180 @Override
181 public boolean equals(Object object) {
182
183 if (!(object instanceof AlbumVO)) {
184 return false;
185 }
186 AlbumVO other = (AlbumVO) object;
187 if ((this.albumid == null && other.albumid != null) || (this.albumid != null && !this.albumid.equals(other.albumid))) {
188 return false;
189 }
190 return true;
191 }
192
193 @Override
194 public String toString() {
195 return this.getClass().getCanonicalName() + "[albumid=" + albumid + "]";
196 }
197
198
199
200
201 public Set<PhotoVO> getPhotos() {
202 return photos;
203 }
204
205
206
207
208 public void addPhotos(HashSet<PhotoVO> photos) {
209 this.photos.addAll(photos);
210 }
211
212
213
214
215 public void addPhoto(PhotoVO photos) {
216 this.photos.add(photos);
217 }
218
219
220
221
222
223
224 public PhotoVO getPhotoBy(Integer id) {
225 return new ArrayList<PhotoVO>(this.photos).get(id);
226 }
227
228
229
230
231
232
233
234 public boolean removePhotoBy(Integer id) {
235 return this.photos.remove(getPhotoBy(id));
236 }
237
238
239
240
241
242 @Override
243 public Integer getId() {
244 return this.albumid;
245 }
246 }